package com.example.gm.entity;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;

import lombok.Data;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ApiResult implements Serializable {
	private static final long serialVersionUID = 1L;
	
	//结果代码，=0成功，其他值对应错误码
	int code;
	//结果信息
	String message;
	//结果数据
	Object data;
	
	//静态构造帮助函数
    public static ApiResult create(int code, String message, Object data){
    	ApiResult result = new ApiResult();
    	result.setCode(code);
    	result.setMessage(message);
    	result.setData(data);
    	return result;
    }
	
	//返回成功的静态帮助函数
    public static ApiResult ok(){
        return create(GmConst.ERROR_OK, null, null);
    }
    public static ApiResult ok(String message){
        return create(GmConst.ERROR_OK, message, null);
    }
    public static ApiResult ok(Object data){
        return create(GmConst.ERROR_OK, null, data);
    }
    public static ApiResult ok(String message, Object data){
        return create(GmConst.ERROR_OK, message, data);
    }
	
	//返回通用失败的静态帮助函数
    public static ApiResult error(){
        return create(GmConst.ERROR_UNKNOW, null, null);
    }
    public static ApiResult error(String message){
        return create(GmConst.ERROR_UNKNOW, message, null);
    }
    public static ApiResult error(Object data){
        return create(GmConst.ERROR_UNKNOW, null, data);
    }
    public static ApiResult error(String message, Object data){
        return create(GmConst.ERROR_UNKNOW, message, data);
    }
}
